<?php
 /*****************************************************************************
 * editInvoice.php                                                            *
 * Last Modified: 2007-06-06                                                  *
 *                                                                            *
 * editInvoice.php outputs an HTML form populated with data from tblInvoices  *
 * to be used to update the data stored in the invoice record.                *
 *                                                                            *
 * BBG_Billing, a PHP application using MySQL for creating and maintaining a  *
 * contacts and invoices database.                                            *
 *                                                                            *
 * @copyright Copyright (C) 2007, Bugs Bee Gone Computer Services             *
 * @owner     Daniel Barnett (Bugs Bee Gone Computer Services)                *
 * @author    Daniel Barnett <dbarnett@bugsbeegone.com>                       *
 * @website   http://www.bugsbeegone.com                                      *
 * @license   http://www.gnu.org/licenses/gpl.html GNU General Public License *
 * @package   BBG_Billing                                                     *
 * @name      editInvoice.php                                                 *
 * @version   1.0.0                                                           *
 * @uses      Jpmaster77's Login Script (Written by: Jpmaster77, 2004-08-19)  *
 *             ->(http://www.evolt.org/PHP-Login-System-with-Admin-Features/) *
 *                                                                            *
 * This file is part of the "BBG_Billing" PHP application.                    *
 *                                                                            *
 * BBG_Billing is free software; you can redistribute it and/or modify        *
 * it under the terms of the GNU General Public License as published by       *
 * the Free Software Foundation; either version 2 of the License, or          *
 * (at your option) any later version.                                        *
 *                                                                            *
 * BBG_Billing is distributed in the hope that it will be useful,             *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
 * GNU General Public License for more details.                               *
 *                                                                            *
 * You should have received a copy of the GNU General Public License          *
 * along with BBG_Billing; if not, write to the Free Software                 *
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA *
 *****************************************************************************/
 
 
  // Require session.php for user access control
	require "include/session.php";

  // If user is not logged in, redirect to main.php
	if(!$session->logged_in){
		header("Location: main.php");
		exit();
	}

  // Require config.inc.php for configuration variables
	require_once "config.inc.php";

  // Connect to MySQL
	mysql_connect($path, $username, $password);
	// Select the database, if error die with error message
	@mysql_select_db($database) or die("Unable to select database.<br />" . mysql_error());

  // Get invoiceNum value from URL
	$invoiceNum = $_GET['invoiceNum'];

  // Define MySQL query
	$query = "SELECT * FROM `tblInvoices` WHERE `invoiceNum`=$invoiceNum LIMIT 1";

  // Execute MySQL query, if error die with error message
	$result = mysql_query($query) or die(mysql_error());

  // Determine number of rows returned
	$num = mysql_numrows($result);

  // Close connection
	mysql_close();

  // If num = 1...
	if($num == 1) {
         // Define data variables
         $key = mysql_result($result,0,"key");
         $date = mysql_result($result,0,"date");
         $invoiceNum = mysql_result($result,0,"invoiceNum");
         $customerID = mysql_result($result,0,"customerID");
			
         $item1Qty = mysql_result($result,0,'item1Qty');
         $item2Qty = mysql_result($result,0,'item2Qty');
         $item3Qty = mysql_result($result,0,'item3Qty');
         $item4Qty = mysql_result($result,0,'item4Qty');
         $item5Qty = mysql_result($result,0,'item5Qty');
         $item6Qty = mysql_result($result,0,'item6Qty');
         $item7Qty = mysql_result($result,0,'item7Qty');
         $item8Qty = mysql_result($result,0,'item8Qty');
         $item9Qty = mysql_result($result,0,'item9Qty');
         $item10Qty = mysql_result($result,0,'item10Qty');

         $item1Name = mysql_result($result,0,'item1Name');
         $item2Name = mysql_result($result,0,'item2Name');
         $item3Name = mysql_result($result,0,'item3Name');
         $item4Name = mysql_result($result,0,'item4Name');
         $item5Name = mysql_result($result,0,'item5Name');
         $item6Name = mysql_result($result,0,'item6Name');
         $item7Name = mysql_result($result,0,'item7Name');
         $item8Name = mysql_result($result,0,'item8Name');
         $item9Name = mysql_result($result,0,'item9Name');
         $item10Name = mysql_result($result,0,'item10Name');

         $item1Rate = mysql_result($result,0,'item1Rate');
         $item2Rate = mysql_result($result,0,'item2Rate');
         $item3Rate = mysql_result($result,0,'item3Rate');
         $item4Rate = mysql_result($result,0,'item4Rate');
         $item5Rate = mysql_result($result,0,'item5Rate');
         $item6Rate = mysql_result($result,0,'item6Rate');
         $item7Rate = mysql_result($result,0,'item7Rate');
         $item8Rate = mysql_result($result,0,'item8Rate');
         $item9Rate = mysql_result($result,0,'item9Rate');
         $item10Rate = mysql_result($result,0,'item10Rate');

         $item1Total = mysql_result($result,0,'item1Total');
         $item2Total = mysql_result($result,0,'item2Total');
         $item3Total = mysql_result($result,0,'item3Total');
         $item4Total = mysql_result($result,0,'item4Total');
         $item5Total = mysql_result($result,0,'item5Total');
         $item6Total = mysql_result($result,0,'item6Total');
         $item7Total = mysql_result($result,0,'item7Total');
         $item8Total = mysql_result($result,0,'item8Total');
         $item9Total = mysql_result($result,0,'item9Total');
         $item10Total = mysql_result($result,0,'item10Total');

         $discount = mysql_result($result,0,'discount');
         $tax = mysql_result($result,0,'tax');
         $subTotal = mysql_result($result,0,'subTotal');
         $total = mysql_result($result,0,'total');
         $notes = mysql_result($result,0,'notes');
  // If num != 1...
	} else {
         // Die with error message
         die('<p style="color: red;">Database error...<br />Record ID Not Found.</p><br />');
	}
	
  // Output data objects (using a POST form)
  echo '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . "\n";
?>

<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta name="ROBOTS" content="NOODP, NOFOLLOW" />
		<meta name="GOOGLEBOT" content="NOODP, NOFOLLOW" />
		<title>Bugs Bee Gone - Billing - Edit Invoice</title>
		<meta name="description" content="Bugs Bee Gone - Billing - Edit Invoice" />
		<meta name="keywords" content="php, mysql, test, practice" />
		<link rel="shortcut icon" href="" />
		<link href="invoice.css" type="text/css" rel="stylesheet" />

		<script type="text/javascript" src="func.inc.js"></script>
	</head>

	<body>

	<div style="text-align: center;">
	<p>Update Record:</p>
	<form action="updateInvoice.php" method="post">
			<input type="hidden" name="invoiceNum" value="<? echo $invoiceNum; ?>" />
		<table width="600px" align="center" cellspacing="4" cellpadding="2" style="border-style:solid;border-width:1px;border-color:black;">
		<tr>
			<td valign="top" width="150px">
				<b>Invoice Number:</b>
			</td>

			<td valign="top" colspan="2">
				<?php echo $invoiceNum; ?>
			</td>
		</tr>

		<tr>
			<td valign="top" width="150px">
				<b>Invoice Date:</b>
			</td>

			<td valign="top" colspan="2">
				<input type="text" name="date" class="required" value="<?php echo $date; ?>" />
			</td>
		</tr>

		<tr>
			<td valign="top" width="150px">
				<b>Customer ID:</b>
			</td>

			<td valign="top" colspan="2">
				<input type="text" name="customerID" class="required" value="<?php echo $customerID; ?>" />
			</td>
		</tr>

		<?

				echo '<tr>' . "\n";
				echo '<td valign="top" colspan="3" style="background-color:#F8F8FF;">' . "\n";
					echo '<b><u>Item 1</u></b>' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Qty</b>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Name</b>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Rate</b>' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" width="150px">' . "\n";
						echo '<input type="text" name="item1Qty" class="required" value="'.$item1Qty.'" />' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<textarea rows="3" cols="20" name="item1Name" class="required" onkeypress="return checkMaxLength(event,this)" TAMaxLength="100">'.$item1Name.'</textarea>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<input type="text" name="item1Rate" class="required" value="'.$item1Rate.'" />' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" colspan="3" style="background-color:#F8F8FF;">' . "\n";
					echo '<b><u>Item 2</u></b>' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Qty</b>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Name</b>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Rate</b>' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" width="150px">' . "\n";
						echo '<input type="text" name="item2Qty" class="required" value="'.$item2Qty.'" />' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<textarea rows="3" cols="20" name="item2Name" class="required" onkeypress="return checkMaxLength(event,this)" TAMaxLength="100">'.$item2Name.'</textarea>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<input type="text" name="item2Rate" class="required" value="'.$item2Rate.'" />' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" colspan="3" style="background-color:#F8F8FF;">' . "\n";
					echo '<b><u>Item 3</u></b>' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Qty</b>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Name</b>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Rate</b>' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" width="150px">' . "\n";
						echo '<input type="text" name="item3Qty" class="required" value="'.$item3Qty.'" />' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<textarea rows="3" cols="20" name="item3Name" class="required" onkeypress="return checkMaxLength(event,this)" TAMaxLength="100">'.$item3Name.'</textarea>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<input type="text" name="item3Rate" class="required" value="'.$item3Rate.'" />' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" colspan="3" style="background-color:#F8F8FF;">' . "\n";
					echo '<b><u>Item 4</u></b>' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Qty</b>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Name</b>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Rate</b>' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" width="150px">' . "\n";
						echo '<input type="text" name="item4Qty" class="required" value="'.$item4Qty.'" />' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<textarea rows="3" cols="20" name="item4Name" class="required" onkeypress="return checkMaxLength(event,this)" TAMaxLength="100">'.$item4Name.'</textarea>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<input type="text" name="item4Rate" class="required" value="'.$item4Rate.'" />' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" colspan="3" style="background-color:#F8F8FF;">' . "\n";
					echo '<b><u>Item 5</u></b>' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Qty</b>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Name</b>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Rate</b>' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" width="150px">' . "\n";
						echo '<input type="text" name="item5Qty" class="required" value="'.$item5Qty.'" />' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<textarea rows="3" cols="20" name="item5Name" class="required" onkeypress="return checkMaxLength(event,this)" TAMaxLength="100">'.$item5Name.'</textarea>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<input type="text" name="item5Rate" class="required" value="'.$item5Rate.'" />' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" colspan="3" style="background-color:#F8F8FF;">' . "\n";
					echo '<b><u>Item 6</u></b>' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Qty</b>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Name</b>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Rate</b>' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" width="150px">' . "\n";
						echo '<input type="text" name="item6Qty" class="required" value="'.$item6Qty.'" />' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<textarea rows="3" cols="20" name="item6Name" class="required" onkeypress="return checkMaxLength(event,this)" TAMaxLength="100">'.$item6Name.'</textarea>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<input type="text" name="item6Rate" class="required" value="'.$item6Rate.'" />' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" colspan="3" style="background-color:#F8F8FF;">' . "\n";
					echo '<b><u>Item 7</u></b>' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Qty</b>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Name</b>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Rate</b>' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" width="150px">' . "\n";
						echo '<input type="text" name="item7Qty" class="required" value="'.$item7Qty.'" />' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<textarea rows="3" cols="20" name="item7Name" class="required" onkeypress="return checkMaxLength(event,this)" TAMaxLength="100">'.$item7Name.'</textarea>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<input type="text" name="item7Rate" class="required" value="'.$item7Rate.'" />' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" colspan="3" style="background-color:#F8F8FF;">' . "\n";
					echo '<b><u>Item 8</u></b>' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Qty</b>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Name</b>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Rate</b>' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" width="150px">' . "\n";
						echo '<input type="text" name="item8Qty" class="required" value="'.$item8Qty.'" />' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<textarea rows="3" cols="20" name="item8Name" class="required" onkeypress="return checkMaxLength(event,this)" TAMaxLength="100">'.$item8Name.'</textarea>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<input type="text" name="item8Rate" class="required" value="'.$item8Rate.'" />' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" colspan="3" style="background-color:#F8F8FF;">' . "\n";
					echo '<b><u>Item 9</u></b>' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Qty</b>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Name</b>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Rate</b>' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" width="150px">' . "\n";
						echo '<input type="text" name="item9Qty" class="required" value="'.$item9Qty.'" />' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<textarea rows="3" cols="20" name="item9Name" class="required" onkeypress="return checkMaxLength(event,this)" TAMaxLength="100">'.$item9Name.'</textarea>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<input type="text" name="item9Rate" class="required" value="'.$item9Rate.'" />' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" colspan="3" style="background-color:#F8F8FF;">' . "\n";
					echo '<b><u>Item 10</u></b>' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Qty</b>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Name</b>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<b>Rate</b>' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

				echo '<tr>' . "\n";
				echo '<td valign="top" width="150px">' . "\n";
						echo '<input type="text" name="item10Qty" class="required" value="'.$item10Qty.'" />' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<textarea rows="3" cols="20" name="item10Name" class="required" onkeypress="return checkMaxLength(event,this)" TAMaxLength="100">'.$item10Name.'</textarea>' . "\n";
				echo '</td>' . "\n";

				echo '<td valign="top" width="150px">' . "\n";
						echo '<input type="text" name="item10Rate" class="required" value="'.$item10Rate.'" />' . "\n";
				echo '</td>' . "\n";
				echo '</tr>' . "\n";

		?>
		<tr>
			<td valign="top" width="150px">
				<b>Discount:</b>
			</td>

			<td valign="top" colspan="2">
				<input type="text" name="discount" value="<?php echo $discount; ?>" />
			</td>
		</tr>

		<tr>
			<td valign="top" width="150px">
				<b>Tax Rate:</b>
			</td>

			<td valign="top" colspan="2">
				<input type="text" name="taxRate" value="<?php echo $taxRate; ?>" />

			</td>
		</tr>

		<tr>
			<td valign="top" width="150px">
				<b>Notes:</b>
			</td>

			<td valign="top" colspan="2">
				<textarea rows="4" cols="40" name="notes" onkeypress="return checkMaxLength(event,this)" TAMaxLength="400"><?php echo $notes; ?></textarea>
			</td>
		</tr>
		</table>

		<input type="Submit" value="Update Invoice" /> <input type="button" onclick="cancel(this)" location="invoices.php" value="Cancel" />
		</form>
		</div>

	</body>
</html>
